home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1990-1992 Michael Davidson.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for any purpose and without fee is hereby
- * granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission
- * notice appear in supporting documentation.
- *
- * This software is provided "as is" without express or implied warranty.
- */
-
- /*
- * vbios.c - interface to video bios functions
- */
- #include <unistd.h>
-
- #include "v86mode.h"
- #include "vbios.h"
-
- #define MEMFILE "/dev/mem"
-
- STATIC int VBiosMemLoad(char *file, long off, long virt, long len);
- STATIC int VBiosChecksum(unsigned char *b);
- STATIC void VBiosINT10Init();
-
- unsigned char *VideoBiosAddress;
-
- /*
- * VBiosInit() - initialise video BIOS
- */
- int
- VBiosInit()
- {
- int r;
- unsigned long v;
-
- /*
- * initialise the V86 mode environment
- */
- if ((r = V86Init()) != 0)
- return r;
-
- /*
- * map the display adaptor memory
- */
- if ((r = V86MemMap((paddr_t)0xa0000, (caddr_t)0xa0000, 0x20000)) != 0)
- return r;
-
- /*
- * enable i/o to the display adaptor
- */
- if ((r = V86IOEnable(0x3b0, 0x30)) != 0)
- return r;
-
- /*
- * load the real-mode interrupt vectors and BIOS data area
- */
- if ((r = VBiosMemLoad(MEMFILE, 0x0, 0x0, 0x1000)) != 0)
- return r;
-
- /*
- * use the INT 10 vector to locate the video BIOS
- */
- v = ((unsigned long *) 0)[0x10];
- v = (v & 0xffff0000) >> 12;
-
- /*
- * load the video BIOS
- */
- if ((r = VBiosMemLoad(MEMFILE, v, v, 0x8000)) != 0)
- return r;
-
- /*
- * checksum the video BIOS
- */
- if ((r = VBiosChecksum((unsigned char *)v)) != 0)
- return r;
-
- VideoBiosAddress = (unsigned char *) v;
-
- /*
- * load the system BIOS
- */
- if ((r = VBiosMemLoad(MEMFILE, 0xf0000, 0xf0000, 0x10000)) != 0)
- return r;
-
-
- VBiosINT10Init();
-
- return 0;
- }
-
- /*
- * VBiosMemLoad() - load V86 address space from a file
- */
- STATIC int
- VBiosMemLoad(
- char *file,
- long off,
- long virt,
- long len
- )
- {
- int fd;
- extern long lseek(int, long, int);
-
- if ((fd = open(file, 0)) < 0)
- return -1;
-
- if (lseek(fd, off, 0) != off || read(fd, (char *) virt, len) != len)
- {
- close(fd);
- return -1;
- }
-
- close(fd);
-
- return 0;
- }
-
- /*
- * VBiosChecksum() - check the integrity of the video BIOS
- */
- STATIC int
- VBiosChecksum(
- unsigned char *b
- )
- {
- int c;
- int n;
-
- if (b[0] != 0x55 || b[1] != 0xaa)
- return -1;
-
- n = b[2] * 512;
- c = 0;
- while (--n >= 0)
- c += *b++;
-
- return (c & 0xff);
- }
-
- STATIC word_t vbios_cs;
- STATIC word_t vbios_ip;
- STATIC word_t vbios_ss;
- STATIC word_t vbios_sp;
-
- STATIC void
- VBiosINT10Init()
- {
- byte_t *p;
-
- vbios_cs = VBIOS_SEG;
- vbios_ip = 0;
- vbios_ss = VBIOS_SEG;
- vbios_sp = 0xfffe;
-
- p = (byte_t *) (vbios_cs << 4);
-
- /*
- * put an INT 10 followed by a HLT instruction at the start of the segment
- */
- p[0] = 0xcd;
- p[1] = 0x10;
- p[2] = 0xf4;
-
- p[0xfffe] = 0;
- p[0xffff] = 0;
- }
-
- void
- VBiosINT10()
- {
- register struct tss386 *t = v86tss;
- int r;
-
- CS(t) = vbios_cs;
- IP(t) = vbios_ip;
- SS(t) = vbios_ss;
- SP(t) = vbios_sp;
-
- if ((r = V86Run()) != ERR_V86_HALT)
- fatal(0, "V86 mode error: %s", V86ErrorMessage(r));
- }
-
- void *
- VBiosGetFontInfo(
- int code
- )
- {
- register struct tss386 *t = v86tss;
-
- AX(t) = 0x1130;
- BL(t) = 0;
- BH(t) = (byte_t) code;
-
- VBiosINT10();
-
- return (void *) ((ES(t) << 4) | BP(t));
- }
-
- int
- VBiosSetMode(
- int mode
- )
- {
- register struct tss386 *t = v86tss;
-
- AH(t) = 0;
- AL(t) = (byte_t) mode;
-
- VBiosINT10();
-
- return AX(t);
- }
-
- int
- VBiosGetMode()
- {
- register struct tss386 *t = v86tss;
-
- AH(t) = 0x0f;
-
- VBiosINT10();
-
- return AL(t);
- }
-
- int
- VBiosDisableBlink()
- {
- register struct tss386 *t = v86tss;
-
- AH(t) = 0x10;
- AL(t) = 0x03;
-
- VBiosINT10();
-
- return 0;
- }
-
- int
- VBiosSetCursorPosition(
- int x,
- int y
- )
- {
- register struct tss386 *t = v86tss;
-
- AH(t) = 0x02;
- AL(t) = 0x00;
- BX(t) = 0;
- CX(t) = 0;
- DH(t) = (byte_t) y;
- DL(t) = (byte_t) x;
-
- VBiosINT10();
-
- return 0;
- }
-
-